﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;
using Besture.Model;


namespace Besture.UI.Admin.Modules
{
    public partial class ModulesSet : BasePage
    {
        /// <summary>
        /// 
        /// </summary>

        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            if (Request.QueryString["id"] != null && !string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                //编辑编号
                hidEditID.Value = Request.QueryString["id"];
                if (!StringHelper.IsNumber(hidEditID.Value))
                {
                    RedirectErrorUrl("编号错误");
                }
                InitData(Convert.ToInt32(hidEditID.Value));
            }

        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }

        /// <summary>
        /// 数据加载
        /// </summary>
        /// <param name="id">编号</param>
        protected void InitData(int id)
        {
            AdminPagesDac dac = new AdminPagesDac();
            AdminPagesModel model = dac.GetModel(id);
            Name.Text = model.Name;
            cmsAdminPage.PageUrl = model.PageUrl;
            SortID.Text = model.SortID.ToString();
        }
        #endregion

        #region 保存

        protected void btnSubmit_Click(object sender, EventArgs eventArgs)
        {
            AdminPagesDac dac = new AdminPagesDac();
            AdminPagesModel model = null;
            string editID = hidEditID.Value;
            //添加
            if (string.IsNullOrEmpty(editID))
            {
                model = new AdminPagesModel();
                model.Name = Name.Text.Trim();
                model.PageUrl = cmsAdminPage.PageUrl;
                model.ModulesID = 0;
                model.SortID = Convert.ToInt32(SortID.Text.Trim());
                model.Remarks = "";
                dac.Add(model);
            }
            //编辑
            else
            {
                model = dac.GetModel(Convert.ToInt32(editID));
                model.Name = Name.Text.Trim();
                model.PageUrl = cmsAdminPage.PageUrl;
                model.ModulesID = 0;
                model.SortID = Convert.ToInt32(SortID.Text.Trim());
                model.Remarks = "";
                dac.Update(model);
            }
            FunHelper.Alert("保存成功", "ModulesList.aspx");
        }
        #endregion

        #region 取消

        public void btnCanel_Click(object sender, EventArgs eventArgs)
        {
            RedirectUrl("ModulesList.aspx");
        }

        #endregion
    }
}